package com.example.dao;

import com.example.domain.t_user;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface UserMapper {
    //查找用户（username）
    @Select("select * from t_user where username=#{username}")
    public t_user selectByUsername(String username);
    //查找用户（Email，id）
    @Select("select * from t_user where email=#{email}")
    public t_user selectByEmail(String email);
    @Select("select * from t_user where id=#{id}")
    public t_user selectById(int id);

    //获取用户权限
    @Select("select a.authority " +
            "from t_user u,t_authority a,t_user_authority ua " +
            "where ua.user_id=u.id and ua.authority_id=a.id and u.id=#{user_id}")
    public String selectUserAuthority(int user_id);

    //注册(t_user,t_user_authoriy)
    @Insert("insert into t_user(id,username,password,email,created,valid) " +
            "values(null,#{username},#{password},#{email},#{created},#{valid})")
    public boolean insertOneUser(t_user user);
    @Insert("insert into t_user_authority values(null,#{id},2)")
    public boolean insertOneAuth(int id);
    //修改用户激活标识
    @Update("update t_user set valid=#{valid} where email=#{email}")
    void setUserVail(String email, boolean valid);

    boolean updateUserById(t_user loginUser);

    //更新用户头像信息
    @Update("update t_user set avatar=#{avatar} where id=#{id}")
    void updateAvatarById(String avatar, int id);

    //查找用户头像信息
    @Select("select avatar from t_user where id=#{id}")
    String getAvatarById(int id);
    @Select("select avatar from t_user where username=#{author}")
    String getAvatarByAuthor(String author);
}
